package com.xingkeduo.business.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xingkeduo.business.transformation.json.BaseDTOJTO;
import com.xingkeduo.business.transformation.json.ConsumerPrivateJTO;
import com.xingkeduo.business.user.domain.ConsumerDomain;
import com.xingkeduo.pojo.phppojo.ResponseResult;
import com.xingkeduo.pojo.query.ConsumerPrivateQO;
import com.xingkeduo.pojo.table.ConsumerPrivateTO;
import com.xingkeduo.util.pojo.base.BaseController;
import com.xingkeduo.util.pojo.exception.DataException;

/**
 * @Description:
 * @Author:pantong
 * @Date 2019/4/29 10:00
 **/
@RestController
@RequestMapping("/consumerPrivate")
public class ConsumerPrivateController extends BaseController {

    @Autowired
    private ConsumerDomain consumerDomain;
    
    /**
     * 查询年龄标签列表
     * @param f_user_id
     * @param time
     * @param token
     * @param mobile_type
     * @author : pantong
     * @return
     * @throws Throwable
     */
    @GetMapping("/update_age")
    public Object update_age(long f_user_id, String time, String token, String mobile_type) throws Throwable{
    	try {
    		ConsumerPrivateQO consumerPrivateQO = new ConsumerPrivateQO();
    		consumerPrivateQO.setId(f_user_id);
    		
    		ConsumerPrivateTO consumerPrivateTO = consumerDomain.getConsumerPrivate(consumerPrivateQO);
    		return BaseDTOJTO.toSuccessJson(ConsumerPrivateJTO.toJsonAge(consumerPrivateTO));
    	}catch (DataException e) {
    		dealException(e);
    		return BaseDTOJTO.toErrorJson(e.getMessage());
    	}catch (Exception e) {
    		dealException(e);
    		return BaseDTOJTO.toErrorJson("操作失败，请稍后重试！");
		}
    }
    

    /**
     * 修改年龄标签
     * @param f_user_id
     * @param time
     * @param token
     * @param choose_style_list_ids
     * @param mobile_type
     * @return
     * @throws Throwable
     */
    @GetMapping("/ajax_update_age")
    public Object ajax_update_age(long f_user_id, String time, String token, int selected_tag, String mobile_type) throws Throwable {
        try {
            consumerDomain.updateConsumerPrivateAge(f_user_id, time, token, selected_tag, mobile_type);
            return new ResponseResult().success();
        }catch (DataException e) {
        	dealException(e);
        	return BaseDTOJTO.toErrorJson(e.getMessage());
    	}catch (Exception e) {
    		dealException(e);
    		return BaseDTOJTO.toErrorJson("修改失败，请稍后重试！");
		}
    }
    
    /**
     * 查询性别标签列表
     * @param f_user_id
     * @param time
     * @param token
     * @param mobile_type
     * @author : pantong
     * @return
     * @throws Throwable
     */
    @GetMapping("/update_sex")
    public Object update_sex(long f_user_id, String time, String token, String mobile_type) throws Throwable{
    	try {
    		ConsumerPrivateQO consumerPrivateQO = new ConsumerPrivateQO();
    		consumerPrivateQO.setId(f_user_id);
    		
    		ConsumerPrivateTO consumerPrivateTO = consumerDomain.getConsumerPrivate(consumerPrivateQO);
    		return BaseDTOJTO.toSuccessJson(ConsumerPrivateJTO.toJsonSex(consumerPrivateTO));
    	}catch (DataException e) {
    		dealException(e);
    		return BaseDTOJTO.toErrorJson(e.getMessage());
    	}catch (Exception e) {
    		dealException(e);
    		return BaseDTOJTO.toErrorJson("操作失败，请稍后重试！");
		}
    }
    

    /**
     * 修改性别标签
     * @param f_user_id
     * @param time
     * @param token
     * @param choose_style_list_ids
     * @param mobile_type
     * @return
     * @throws Throwable
     */
    @GetMapping("/ajax_update_sex")
    public Object ajax_update_sex(long f_user_id, String time, String token, int f_sex, String mobile_type) throws Throwable {
        try {
            consumerDomain.updateConsumerPrivateSex(f_user_id, time, token, f_sex, mobile_type);
            return new ResponseResult().success();
        }catch (DataException e) {
        	dealException(e);
			return BaseDTOJTO.toErrorJson(e.getMessage());
    	}catch (Exception e) {
    		dealException(e);
    		return BaseDTOJTO.toErrorJson("修改失败，请稍后重试！");
		}
    }
    
    
    /**
     * 查询职业属性标签列表
     * @param f_user_id
     * @param time
     * @param token
     * @param mobile_type
     * @author : pantong
     * @return
     * @throws Throwable
     */
    @GetMapping("/update_work")
    public Object update_work(long f_user_id, String time, String token, String mobile_type) throws Throwable{
    	try {
    		ConsumerPrivateQO consumerPrivateQO = new ConsumerPrivateQO();
    		consumerPrivateQO.setId(f_user_id);
    		
    		ConsumerPrivateTO consumerPrivateTO = consumerDomain.getConsumerPrivate(consumerPrivateQO);
    		return BaseDTOJTO.toSuccessJson(ConsumerPrivateJTO.toJsonWork(consumerPrivateTO));
    	}catch (DataException e) {
    		dealException(e);
    		return BaseDTOJTO.toErrorJson(e.getMessage());
    	}catch (Exception e) {
    		dealException(e);
    		return BaseDTOJTO.toErrorJson("操作失败，请稍后重试！");
		}
    }
    

    /**
     * 修改职业属性标签
     * @param f_user_id
     * @param time
     * @param token
     * @param choose_style_list_ids
     * @param mobile_type
     * @return
     * @throws Throwable
     */
    @GetMapping("/ajax_update_work")
    public Object ajax_update_work(long f_user_id, String time, String token, int f_professional_attributes, String mobile_type) throws Throwable {
        try {
            consumerDomain.updateConsumerPrivateCareer(f_user_id, time, token, f_professional_attributes, mobile_type);
            return new ResponseResult().success();
        }catch (DataException e) {
        	dealException(e);
			return BaseDTOJTO.toErrorJson(e.getMessage());
    	}catch (Exception e) {
    		dealException(e);
    		return BaseDTOJTO.toErrorJson("修改失败，请稍后重试！");
		}
    }
    
}
